<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>数学公式：KaTeX，MathJax 引擎切换/设置 MathJax 宏定义/允许 $ 后出现数字 - Vditor</title>
    <meta name="robots" content="index,follow,archive">
    <meta name="description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="copyright" content="B3log"/>
    <link rel="canonical" href="https://b3log.org/vditor/demo/advanced-math.html">
    <link rel="apple-touch-icon" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Window-target" content="_top"/>
    <link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png"/>
    <link rel="shortcut icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-512.png"/>
    <link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@7582df6ba7d52434a3e229cdbd56a06ae62b45c6/src/css/base.css" charset="utf-8"/>

    <meta property="og:locale" content="zh_CN"/>
    <meta property="og:title" content="数学公式：KaTeX，MathJax 引擎切换/设置 MathJax 宏定义/允许 $ 后出现数字 - Vditor"/>
    <meta property="og:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta property="og:image" content="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png"/>
    <meta property="og:url" content="https://b3log.org/vditor"/>
    <meta property="og:site_name" content="B3log"/>
    <meta name="twitter:card" content="summary_large_image"/>
    <meta name="twitter:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="twitter:title" content="数学公式：KaTeX，MathJax 引擎切换/设置 MathJax 宏定义/允许 $ 后出现数字 - Vditor"/>
    <meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png"/>
    <meta name="twitter:url" content="https://b3log.org/vditor"/>
    <meta name="twitter:site" content="@b3logos"/>
    <meta name="twitter:creator" content="@b3logos"/>
    <script src="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/vditor/vditor.js" defer></script>
    <style>
        .header {
            background-color: #fff;
            box-shadow: rgba(0, 0, 0, 0.05) 0 1px 7px;
            border-bottom: 1px solid #e1e4e8;
        }
    </style>
</head>
<body>
<div class="header fn-clear">
    <a class="header-logo" href="https://b3log.org/vditor">
        <img src="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png">
        <h1>Vditor</h1>
    </a>
    <div class="fn-clear">
        <a class="header-a" href="https://ld246.com/tag/vditor" target="_blank">社区</a>
        <a class="header-a header-red" target="_blank" href="https://ld246.com/article/1549638745630">API</a>
        <a class="header-a header-green current" href="index.html">Demo</a>
        <a class="header-a header-yellow" href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
    </div>
</div>
<div class="wrapper">
    <div class="fn-50"></div>
    相关 <a href="https://ld246.com/article/1549638745630#options-preview-math" target="_blank">API</a>：
    options.preview.math.inlineDigit，options.preview.math.macros，options.preview.math.engine
    <div class="fn-50"></div>
    <button class="btn--small btn" onclick="setMath(this, {preview: {math:{engine:'KaTeX'}}})">使用 KaTeX 渲染</button> &nbsp;
    <button class="btn--small btn" onclick="setMath(this, {preview: {math:{engine:'MathJax', macros:{bf: '{\\boldsymbol f}', bu: '{\\boldsymbol u}',bv: '{\\boldsymbol v}',bw: '{\\boldsymbol w}'}}}})">使用 MathJax 及宏渲染</button> &nbsp;
    <button class="btn--small btn" onclick="setMath(this, {preview: {math:{inlineDigit:true}}})">允许 $ 后输入数字</button>
    <div id="vditor"></div>
    <div id="vditorDemoCode" class="vditor-reset">
        <pre><code class="javascript">new Vditor('vditor', {
      height: 360,
      typewriterMode: true,
      cache: {
        enable: false,
      },
      value: `数字渲染：
$520$

MathJax macros：

\`\`\`json
macros: {
    bf: '{\\\\boldsymbol f}',
    bu: '{\\\\boldsymbol u}',
    bv: '{\\\\boldsymbol v}',
    bw: '{\\\\boldsymbol w}'
}
\`\`\`

$$
\\bf=\\bu+\\bv-\\bw
$$

多行公式块：

$$
\\frac{1}{
  \\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{
  \\frac25 \\pi}} = 1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {
    1+\\frac{e^{-6\\pi}}
    {1+\\frac{e^{-8\\pi}}{1+\\cdots}}
  }
}
$$

行内公式：

公式 $a^2 + b^2 = \\color{red}c^2$ 是行内。`,
    })</code></pre>
    </div>
    <div class="fn-100"></div>
    <div class="fn-clear">
        <h2 class="fn-left">参与讨论</h2>
        <span class="fn-right" style="line-height: 36px" id="commentCnt"></span>
    </div>
    <div class="fn-50"></div>
    <div id="vditorComments"></div>
    <div class="fn-100"></div>
</div>
<!-- end main -->

<div class="footer">
    <div class="wrapper fn-clear">
        <a href="https://b3log.org">首页</a> &nbsp; &nbsp;
        <a href="https://ld246.com" target="_blank">社区</a> &nbsp; &nbsp;
        <a href="https://b3log.org/brand-marking.html">品牌标识</a> &nbsp; &nbsp;
        <a href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
        <div class="fn-right">
            <a href="https://beian.miit.gov.cn/" target="_blank">滇ICP备14007358号-1</a> &nbsp; &nbsp;
            © 2010-2021 云南链滴科技有限公司
        </div>
    </div>
</div>
<script>
  const setMath = (it, options) => {
    document.getElementById('vditor').innerHTML = ''
    const mergedOptions = Object.assign({
      height: 360,
      typewriterMode: true,
      cache: {
        enable: false,
      },
      value: `数字渲染：
$520$

MathJax macros：

\`\`\`json
macros: {
    bf: '{\\\\boldsymbol f}',
    bu: '{\\\\boldsymbol u}',
    bv: '{\\\\boldsymbol v}',
    bw: '{\\\\boldsymbol w}'
}
\`\`\`

$$
\\bf=\\bu+\\bv-\\bw
$$

多行公式块：

$$
\\frac{1}{
  \\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{
  \\frac25 \\pi}} = 1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {
    1+\\frac{e^{-6\\pi}}
    {1+\\frac{e^{-8\\pi}}{1+\\cdots}}
  }
}
$$

行内公式：

公式 $a^2 + b^2 = \\color{red}c^2$ 是行内。`,
    }, options)

    if (it) {
      updateCode(it, `new Vditor('vditor', ${JSON.stringify(mergedOptions, null, '  ').replace(/\\n/g, `
`).replace(/`/g, '\\`').replace('。"', '。`').replace('"数', '`数')})`)
    }
    new Vditor('vditor', mergedOptions)
  }
  vditorScript = setMath
</script>
</body>
</html>
